package com.goingup.simulation;

import java.util.Random;

import com.goingup.domain.Building;
import com.goingup.domain.Floor;
import com.goingup.domain.Passenger;

public class TripFactory {
	private Building building;

	public TripFactory(Building building)
	{
		this.building = building;
	}
	public void initializeTrip(Passenger passenger)
	{
		System.out.print("Initializing trip\n");
		if (passenger.isOnFloor(building.getGroundFloor()))
			passenger.setDestination(getRandomFloor());
		else
			passenger.setDestination(building.getGroundFloor());
			
		passenger.requestElevator();
	}
	private Floor getRandomFloor() {
		Random random = new Random();
		int randomFloorNumber = random.nextInt(building.floorCount()) + 1;
		return building.getFloor(randomFloorNumber);
	}
}
